package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.EmptyRecyclerView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.SearchAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SearchBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.SearchShopGoodsModel;

public class SearchShopGoodsActivity extends BaseActivity {
    EditText search_content;
    TextView search_sousuo,tv_message,search_fh;
    EmptyRecyclerView search_rv;
    private List<SearchBean> items;
    View search_ev;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_search_shop_goods);
        search_content = (EditText)findViewById(R.id.search_content);
        search_sousuo = (TextView)findViewById(R.id.search_sousuo);
        search_rv = (EmptyRecyclerView)findViewById(R.id.search_rv);
        search_ev = (View)findViewById(R.id.search_ev);
        tv_message = (TextView)findViewById(R.id.tv_message);
        search_fh = (TextView)findViewById(R.id.search_fh);
        tv_message.setText("输入你要搜索的鲜花吧");


    }

    @Override
    void initEvent() {
        search_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        search_sousuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String search = search_content.getText().toString().trim();
                if (search.equals("")){
                    Toast.makeText(SearchShopGoodsActivity.this,"查询关键字不能为空",Toast.LENGTH_SHORT).show();
                }
                else {
                    SearchShopGoodsModel searchShopGoodsModel = new SearchShopGoodsModel();
                    searchShopGoodsModel.SearchShopGoods(search, new ListListener<SearchBean>() {
                        @Override
                        public void onResponse(List<SearchBean> list) {
                            LinearLayoutManager linearLayoutManager=new LinearLayoutManager(SearchShopGoodsActivity.this);
                            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                            search_rv.setLayoutManager(linearLayoutManager);
                            items=list;
                            SearchAdapter searchAdapter=new SearchAdapter(SearchShopGoodsActivity.this,items,R.layout.search_item);
                            search_rv.setAdapter(searchAdapter);
                            search_rv.setItemAnimator(new DefaultItemAnimator());
                            search_rv.setEmptyView(search_ev);
                            tv_message.setText("搜索记录为空");
                        }

                        @Override
                        public void onFail(String msg) {

                        }
                    });
                }
            }
        });

    }

    @Override
    void initDate() {

    }


}
